package jin.si.com.web;

import jin.si.com.entity.User;
import jin.si.com.utils.CacheKeyManager;
import jin.si.com.utils.GuavaUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * @description: 测试谷歌缓存
 * @ClassName TestGuavaController
 * @Author MT
 * @Date 2021/5/26 15:20
 **/

@RestController
@RequestMapping("/guava")
public class TestGuavaController {

    @Autowired
    private TestSSM service;

    @Autowired
    private GuavaUtils guavaUtils;


    @RequestMapping("/getUsers")
    public List<User> getUsers(){

        try {
            Object obj=guavaUtils.getTenCacheBuild().get(CacheKeyManager.INDEX_USER,()->{
                List<User> list = service.getUser();
                System.out.println("*********************************");
                return list;
            });

            if(obj instanceof List){
                List<User> list = (List<User>) obj;
                System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
                return list;
            }

        } catch (ExecutionException e) {
            e.printStackTrace();
        }


        return null;
    }

}
